function  [bdraw,m1,CC1,notmet]=drawnpos_ind(y,x,prm,prprec,sig,ind,tol);
%function [bdraw,m1,CC1,notmet]=drawnpos_ind(y,x,prm,prprec,sig,ind,tol); 
% Draw Coefficients from a Normal distribution when prior is also 
%      Normal( prm, prprec^(-1) )  and prprec is the precision
%      Ind coefficient restricted to be greater than tol 
% 
% y      (Txn) 
% x      (TxK)  
% Prm    (Kx1)  Prior Mean 
% prprec (KxK)  Prior Precision
% sig    (1x1)  Variance of the errors
% position indicator of coefficient to be restricted
% tol     bound, e.g. 0.001 or eps  for positive 
% 
% bdraw  (1xK)  Draw from the posterior normal as a row vector 
% m1     (1xK)  Posterior mean 
% CC1    (KxK)  Cholelsky of the posterior variance 
%               V1= CC1'*CC1  
% nit    Number of draws until constrained satisfied 

% Remove to run faster 
% [ty,ny]=size(y); 
% [tx,nx]=size(x); 
% if tx~=ty
%     error('Not equal number of observations in drawcoef'); 
% end; 
% If the draw is not positive after 5000 draws, indicator notmet = 1, and all
% other arguments are empty. 
% Use drawnpos.m for the standard sampler with rejection
nk=length(prm);
V1=( prprec+ (1/sig)*(x'*x)  ) \ eye(nk) ;   % Posterior Variance  
m1=V1*(prprec*prm + (1/sig)*(x'*y) );        % Posterior Mean  
CC1=chol(V1); 
acc=0;
nit=0; 
rcoun=0; 
while acc < 1 
    bdraw=m1'+ randn(1,nk)*CC1;
    if bdraw(ind) > tol 
        acc=1 ;
        notmet=0; 
    end
    nit=nit+1; 
    if nit == 5000; 
        acc=1; 
        bdraw=[]; 
        notmet=1; 
    end
end 
m1=m1'; 